#include <cratedemo/initialCrateContentDemo1.hpp>

#include <vector>

#include <cratedemo/MiniBall.hpp>

namespace cratedemo
{
	static void addEmpty(CrateContentMap* crate, const char* name)
	{
		std::vector<CrateContent*> vec;
		for(size_t i = 0; i < 4*4; i++)
		{
			vec.push_back(NULL);
		}
		crate->insert(std::pair<std::string, std::vector<CrateContent*> >(name, vec));
	}

	static void add(CrateContentMap* crate, const char* name, datatypes::Color color)
	{
		std::vector<CrateContent*> vec;
		for(size_t i = 0; i < 4*4; i++)
		{
			vec.push_back(new MiniBall(color));
		}
		crate->insert(std::pair<std::string, std::vector<CrateContent*> >(name, vec));
	}
	
	static void addCustom(CrateContentMap* crate, const char* name, datatypes::Color color, int x_empty, int y_empty){
		std::vector<CrateContent*> vec;
		for(int y = 0; y < 4; y++){
			for(int x = 0; x < 4; x++)	{
				if(x_empty == x && y_empty == y){
					vec.push_back(NULL);
				} else {
					vec.push_back(new MiniBall(color));
				}
			}
		}
		crate->insert(std::pair<std::string, std::vector<CrateContent*> >(name, vec));
	}

	void resetCrateContent(int mode){
	/*	std::cout << "================++ THIS IS THE RESETTTTT =============++" << std::endl;
		
		//if (!crateContent1->empty()) {		
		//crateContent1->clear();
		
		delete crateContent1;
		
		crateContent1 = NULL;

		std::cout << "cleared mode: " << mode << std::endl;

		initializeCrateContent1(mode);
	//}
		if (mode == 0){				//1 volle 1 lege
			add("GC4x4MB_1", Color::BLUE);
			addEmpty("GC4x4MB_2");
		} else if(mode == 1){			//1 volle 1 bijna volle
			add("GC4x4MB_1", Color::BLUE);
			addCustom("GC4x4MB_2", Color::RED, 3, 3);
		}
		
		std::cout << "crates initialised?" << std::endl;
		*/
	}

	CrateContentMap& initializeCrateContent1(int mode){
		CrateContentMap* crateMap = new CrateContentMap();
		std::cout << "init" << std::endl;
		
		if (mode == 3){			//1 volle 1 bijna volle
			add(crateMap, "GC4x4MB_1", datatypes::BLUE);
			addCustom(crateMap, "GC4x4MB_2", datatypes::RED, 3, 3);
		} else {				//1 volle 1 lege
			add(crateMap, "GC4x4MB_1", datatypes::BLUE);
			addEmpty(crateMap, "GC4x4MB_2");
		}
		
		return *crateMap;
	}
}
